<template>
  <div class="addroomy">
    <hunk-head name="填写信息"></hunk-head>
    <div class="addform">
      <div class="form-item">
        <div class="name">姓名</div>
        <div class="add-input">
          <uni-easyinput type="text" :inputBorder="false" v-model="addInfo.name" placeholder="请输入您姓名" />
          <!-- <input type="text" placeholder="请输入您姓名" v-model="addInfo.name"> -->
        </div>
      </div>
      <div class="space"></div>
      <div class="form-item">
        <div class="name">手机号</div>
        <div class="add-input">
          <uni-easyinput type="number" :inputBorder="false" v-model="addInfo.telphone" placeholder="请输入您的手机号" />
          <!-- <input type="number" placeholder="请输入您的手机号"  v-model="addInfo.telphone"> -->
        </div>
      </div>
      <div class="space"></div>
      <div class="form-item">
        <div class="name">身份证</div>
        <div class="add-input">
          <uni-easyinput type="text" :inputBorder="false" v-model="addInfo.cardid" placeholder="请输入您身份证" />
          <!-- <input type="text" placeholder="请输入您身份证"  v-model="addInfo.cardid"> -->
        </div>
      </div>
    </div>
    <div class="addbtn" @click="zhuce" >
      确认
    </div>
  </div>
</template>

<script>
import Head from '@componentsMine/head'
import {UpdateHousetuser} from '@/apis/user'
import store from '@store/index'
import {GetUserInfo_openid,getuseropenid} from '@/apis/user'
export default {
  components: {
    'hunk-head': Head
  },
  data() {
    return {
      addInfo: {
        name: '',
        telphone: '',
        cardid:''
      }
    }
  },
  computed:{
    userInfo() {
      return this.$store.state.baseStore.userInfo
    }
  },
  methods: {
    zhuce(){
      if(this.addInfo.name == '' || this.addInfo.cardid == '' || this.addInfo.telphone == ''){
        uni.showToast({
          title: '请填写完整！',
          icon: 'none'
        })
        return
      }else{
        let reg = /^(^\d{18}$|^\d{17}(\d|X|x))$/
        let telreg = /^1[0-9]{10}$/
        if(!reg.test(this.addInfo.cardid)){
          uni.showToast({
            title: '请正确输入身份证',
            icon: 'none'
          })
          return
        }
        if(!telreg.test(this.addInfo.telphone)){
          uni.showToast({
            title: '请正确输入手机号',
            icon: 'none'
          })
          return
        }
      }
      let that = this
      let data = {
        "avatar": this.userInfo.avatar,
        "cardid": this.addInfo.cardid,
        "telphone": this.addInfo.telphone,
        "unickname": this.addInfo.name,
        "userid": this.userInfo.userid
      }
      UpdateHousetuser(data).then(res=>{
        if(res.code == 200){
          wx.setStorageSync('cardid', res.data.cardid)
          store.commit('baseStore/SET_USERINFO', res.data)
          setToken(res.data.token)
          uni.showToast({
            title: res.msg,
            icon: 'none',
            success: ()=>{
              // that.isShouquan()
              uni.redirectTo({ url: '/pages/index/index' })
            }
          })
        }else{
          uni.showToast({
            title: res.msg,
            icon: 'error',
          })
        }
      })
    },
    isShouquan(){
      wx.login({
        success:(res)=> {
          console.log('login',res)
          var code = res.code
          getuseropenid({code}).then(e=>{
            console.log('getuseropenid',typeof(e.data.openid),e.data.openid)
            // if(e.data.openid != 'null'){
              wx.setStorageSync('openid', e.data.openid)
              wx.setStorageSync('session_key', e.data.session_key)
              GetUserInfo_openid({openid:e.data.openid}).then(e=>{
                console.log('执行GetUserInfo_openid',e)
                if(e.code == 200){
                  store.commit('baseStore/SET_USERINFO', e.data)
                  setToken(e.data.token)
                }
              }).catch(e=>{
                
              })
            // }else{
            //   that.isCode = false
            //   that.$refs.wxpopup.open()
            // }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.addroomy {
  width: 100vw;
  box-sizing: border-box;
  height: 100vh;
  position: relative;
  background: #F9F9F9;
  .addform{
    background: #fff;
    .form-item{
      padding: 12px 15px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .name{
        font-size: 15px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #000000;
        line-height: 21px;
      }
      .add-input{
        input{
          font-size: 14px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #4a4a4a;
          line-height: 20px;
          text-align: right;
        }
        input::placeholder{
          color: #9B9B9B;
        }
      }
    }
    .space{
      margin-left: 10px;
      height: 2px;
      border: 1px solid #EFEFEF;
    }
  }
  .addbtn{
    position: absolute;
    bottom: 40px;
    left: 0;
    right: 0;
    margin: auto;
    width: 355px;
    height: 45px;
    background: linear-gradient(315deg, #FFAA58 0%, #FFBD6C 100%);
    box-shadow: 0px 2px 4px 0px rgba(252, 168, 55, 0.21), 0px 3px 5px 0px rgba(255, 175, 111, 0.14);
    border-radius: 100px;
    text-align: center;
    font-size: 16px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #FFFFFF;
    line-height: 45px;
    text-shadow: 0px 2px 4px rgba(252, 168, 55, 0.21);
  }
}
::v-deep .uni-easyinput__content{
  min-height: 20px;
}
::v-deep .uni-easyinput__content-input{
            height: 20px;
            text-align: right;
            font-size: 14px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            line-height: 20px;
            color: #4A4A4A;
            .uni-easyinput__placeholder-class{
              font-size: 14px;
              font-family: PingFangSC-Medium, PingFang SC;
              font-weight: 500;
              line-height: 20px;
              color: #9B9B9B;
              
            }
          }
</style>
